package com.tedu.interceptor.config;

import com.tedu.interceptor.interceptor.MyInterceptor;
import com.tedu.interceptor.interceptor.MyInterceptor1;
import com.tedu.interceptor.interceptor.MyInterceptor2;
import com.tedu.interceptor.interceptor.MyInterceptor3;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration

public class Config implements WebMvcConfigurer {
    //该方法用于向SpringMVC框架中注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*
        注册我们定义的拦截器
        注册后，SpringMVC框架会使用该拦截器拦截请求
        如果我们没有明确拦截路径，啧默认请求服务端的所有路径都要拦截
         */
        //registry.addInterceptor(new MyInterceptor());//都走拦截器
        //registry.addInterceptor(new MyInterceptor()).addPathPatterns("/users/reg");//reg走拦截
       //registry.addInterceptor(new MyInterceptor()).addPathPatterns("/users/reg","/users/login");
        //registry.addInterceptor(new MyInterceptor()).addPathPatterns("/users/**");//跟用户相关的操作会被拦截，其他的不会
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/users/**")
//                .excludePathPatterns("/users/login");//除了登录，其他的用户操作都会拦截
    //注册三个拦截器
    registry.addInterceptor(new MyInterceptor1());
    registry.addInterceptor(new MyInterceptor2());
    registry.addInterceptor(new MyInterceptor3());
    }
}
